8 void make_set(int x
){ p
[x
] = x
, rank
[x
] = 0; }
9 void link(int x
, int y
){ rank
[x
] > rank
[y
] ? p
[y
] = x
: p
[x
] = y
, rank
[x
] == rank
[y
] ? rank
[y
]++: 0; }
10 int find_set(int x
){ return x
!= p
[x
] ? p
[x
] = find_set(p
[x
]) : p
[x
]; }
11 void merge(int x
, int y
){ link(find_set(x
), find_set(y
)); }
20 for (int i
=0; i
<NN
; ++i
) make_set(i
), f
[i
] = 1;
30 if (id
.count(s
)) a
= id
[s
];
31 else a
= id
[s
] = curID
++;
32 if (id
.count(t
)) b
= id
[t
];
33 else b
= id
[t
] = curID
++;
36 if ((i
= find_set(a
)) == (j
= find_set(b
))){
39 int all
= f
[i
] + f
[j
];